package com.weitu.environmental.monitor.controller;


import com.weitu.base.controller.BaseController;
import com.weitu.environmental.monitor.service.MonitorMonthlyReportService;
import com.weitu.paging.DataGridPagination;
import com.weitu.plugin.PageView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhangqingxi 2017-05-10
 */
@Controller
@RequestMapping("environmental/monitor/monthlyReport")
public class MonitorMonthlyReportController extends BaseController {

    private static final String MODULE_BATH_PATH = BASE_JSP_PATH + "environmental/monitor/monthlyReport";

    private final MonitorMonthlyReportService monitorMonthlyReportService;

    @Autowired
    public MonitorMonthlyReportController(MonitorMonthlyReportService monitorMonthlyReportService) {
        this.monitorMonthlyReportService = monitorMonthlyReportService;
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ModelAndView listView() {

        ModelAndView modelAndView = new ModelAndView();

        modelAndView.setViewName(MODULE_BATH_PATH + "/list");

        return modelAndView;
    }


    @ResponseBody
    @RequestMapping("/findByParam")
    public Object findByParam(HttpServletRequest request) {

        Map<String, Object> paramMap = new HashMap<String, Object>();
        //获取前台参数
        putParametersIntoMap(paramMap);
        Integer totalNum = monitorMonthlyReportService.findByParamCount(paramMap);//获取总数
        DataGridPagination pagination = DataGridPagination.getInstance(request, totalNum);

        PageView pageView = pagination.getPageView();//生成pageView分页对象
        paramMap.put("pageView", pageView);

        List<Map> mapList = monitorMonthlyReportService.findByParam(paramMap);

        return pagination.flushDataGridData(mapList);
    }


}
